﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace CSF.Utility.Misc
{
    /// <summary>
    /// 扩展字符串处理方法
    /// </summary>
    public static class StringExtensions
    {
        /// <summary>
        /// 判断字符串是否包含在另一个字符串中
        /// </summary>
        /// <param name="theStr"></param>
        /// <param name="search"></param>
        /// <param name="comparisionType"></param>
        /// <returns></returns>
        public static bool InStr(this string theStr, string search, 
            StringComparison comparisionType = StringComparison.CurrentCultureIgnoreCase)
        {
            return search != null ? search.IndexOf(theStr, comparisionType) >= 0 : false;
        }

        /// <summary>
        /// 判断字符串是否包含在一组字符串的任何一个字符串中
        /// </summary>
        /// <param name="theStr"></param>
        /// <param name="searches"></param>
        /// <param name="comparisionType"></param>
        /// <returns></returns>
        public static bool InStr(this string theStr, string[] searches,
            StringComparison comparisionType = StringComparison.CurrentCultureIgnoreCase)
        {
            if (searches == null)
            {
                throw new ArgumentNullException();
            }
            foreach (var search in searches)
            {
                if (InStr(theStr, search, comparisionType))
                {
                    return true;
                }
            }
            return false;
        }
    }
}
